<include file="public:header" />
    <div class="toptip">
        <h2>提示：</h2>
        <p>系统默认分类不能删除！<br />删除顶级分类将会自动删除此分类下的子分类。</p>
    </div>
    <div class="classification_th">
	  <div class="th1">
	  <label><input type="checkbox" name=" " title="全选/反选" id="J_checkall" />分类标题</label>
	  </div>
	  <div class="th2" style="width:400px">
      <div class="thorder" style="width:80px">类型</div>
      <div class="thorder">排序</div>
      <div class="thedit">操作</div>
      <div class="clear"></div>
	  </div>
	  <div class="clear"></div>
	</div>
    <form id="form1" name="form1" method="post" action="{:U('HelpCategory/allSave')}">
<div class="classification">
<volist name="list" id="list">	
	<div class="menubg">
	  <div class="linput">
	    <div class="td1">
        <input type="checkbox" name="id[]" value="{$list.id}" id="{$list.id}"  class="J_select"/>
      </div>
		 <input name="save_id[]" type="hidden" value="{$list.id}"/>
		<div class="J_show td2" id="{$list.id}" level="1"></div>
		<div class="td3">
      <input name="categoryname[]" type="text" value="{$list.categoryname}" class="input_text_150"  />
    </div>
	  <div class="clear"></div>
	  </div>
	  <div class="edit">
        <div class="order" style="width:90px">
          <if condition="$list['admin_set'] eq 1">
        系统分类
        <else/>
          自定义分类
        </if> 
        </div>
				<div class="order"><input name="category_order[]" type="text"  value="{$list.category_order|default="0"}" class="input_text_50"/></div>
				<div class="edittxt link_lan">
						  <a href="{:U('HelpCategory/add',array('id'=>$list['id']))}">此类下加子类</a>
							<a href="{:U('HelpCategory/edit',array('id'=>$list['id']))}">修改</a>
							<a href="{:U('HelpCategory/delete',array('id'=>$list['id']))}" onclick="return confirm('你确定要删除吗？')">删除</a>
				</div>
				<div class="clear"></div>
	  </div>
	</div>
	 


</volist>
<div class="menubg">
	<div class="add J_add"  level="1" parentid="0">添加顶级分类</div>
</div>


</div>
 <table width="100%" border="0" cellspacing="10"  class="admin_list_btm">
<tr>
        <td>
    <input name="ButSave" type="submit" class="admin_submit" id="ButSave" value="保存分类"/>
        <input name="ButADD" type="button" class="admin_submit" id="ButADD" value="添加分类"  onclick="window.location='{:U('HelpCategory/add')}'"/>
    <input name="ButDel" type="button" class="admin_submit" id="ButDel"  value="删除所选" />
    </td>
        <td width="305" align="right">
    
      </td>
      </tr>
  </table>
</form>
</div>
<include file="public:footer" />
<script type="text/javascript">
$(document).ready(function(){
	$("#ButDel").click(function(){
        if (confirm('你确定要删除吗？'))
        {
            $("form[name=form1]").attr('action',"{:U('HelpCategory/delete')}").submit()
        }
    });
var Maxlevel=2;//最多分类层数
var menu_type = "{$Think.get.type}";
//打开子菜单	
$(".J_show").live('click',function()
        {
			var infobox=$(this).closest(".menubg").next('.j_smalldiv');
			var level=$(this).attr('level');
			infobox.is(':visible')?$(this).removeClass("close"):$(this).addClass("close");	
			if (infobox.length == 0 && level<Maxlevel)
			{
			 get_menu($(this).attr('id'),$(this).closest(".menubg"),level);
			}
			else
			{
			infobox.toggle();		
			}
          
});
//子菜单全选
$(".J_select").live('click',function()
{
	var infobox=$(this).closest(".menubg,.j_smalldiv").next('.j_smalldiv');
	if (infobox.length > 0)
	{
   infobox.find("input[type=checkbox]").attr("checked",this.checked);
   }
});
//全选所有项目
$("#J_checkall").live('click',function()
{
   $(".classification").find("input[type=checkbox]").attr("checked",this.checked);
});
//添加分类
$(".J_add").live('click',function()
{
	var level=$(this).attr('level');
	var parentid=$(this).attr('parentid');
	var html='';
	html+="<div class=\"menubg\">"; 
	html+="<div class=\"linput\">";
	if (level>1)
	{
	html+="<div class=\"sbg l"+level+"\"></div>";
	}
	html+="<div class=\"td1\"><input type=\"checkbox\" name=\"id[]\" value=\"\"/></div>"; 
	html+="<div class=\"J_show td2\"></div>"; 
	html+="<div class=\"td3\"><input name=\"add_name[]\" type=\"text\"  class=\"input_text_150\"   /></div>";
	html+="<input name=\"add_pid[]\" type=\"hidden\" value=\""+parentid+"\"/>";  
	html+="<div class=\"td4\"></div>"; 
	html+="<div class=\"clear\"></div>"; 
	html+="</div>"; 
	html+="<div class=\"edit\">"; 
	html+="<div class=\"order\"><input name=\"add_ordid[]\" type=\"text\"  class=\"input_text_50\"/></div>"; 
	html+="<div class=\"edittxt link_lan\">"; 
	html+="</div>"; 
	html+="<div class=\"clear\"></div>"; 
	html+="</div>"; 
	html+="</div>";
	$(this).parent().before(html);
});
//生成分类
function get_menu(pid,thisobj,level)
{
            var tsTimeStamp= new Date().getTime();
            $.getJSON("{:U('HelpCategory/index')}", {"pid":pid},function(result){  
                    if (result.status==1){
					 var html="";
					 var leftbg="";
                     var i=1;
					 level++;
                        for (x in result.data)
						{
                     		html+="<div class=\"menubg\">"; 
							html+="<div class=\"linput\">";
							html+="<div class=\"sbg l"+level+"\"></div>";
							html+="<div class=\"td1\"><input type=\"checkbox\" name=\"id[]\" value=\""+result.data[x]['id']+"\" id=\""+result.data[x]['id']+"\"  class=\"J_select\"/></div>"; 
							html+="<input name=\"save_id[]\" type=\"hidden\" value=\""+result.data[x]['id']+"\"/>"; 
							html+="<div class=\"J_show td2\" id=\""+result.data[x]['id']+"\" level=\""+level+"\"></div>"; 
							html+="<div class=\"td3\"><input name=\"categoryname[]\" type=\"text\" value=\""+result.data[x]['categoryname']+"\" class=\"input_text_150\"  /></div>";
							html+="<div class=\"clear\"></div>"; 
							html+="</div>"; 
							html+="<div class=\"edit\">"; 
              html+="<div class=\"order\" style=\"width:90px\">";
              if(result.data[x]['admin_set'] == 1){
                html+="系统分类";
              }else{
                html+="自定义分类";
              }
              html+="</div>";
							html+="<div class=\"order\"><input name=\"category_order[]\" type=\"text\"  value=\""+result.data[x]['category_order']+"\" class=\"input_text_50\"/></div>"; 
							html+="<div class=\"edittxt link_lan\">";
							html+="<a href=\"{:U('HelpCategory/edit')}&id="+result.data[x]['id']+"\">修改</a>"; 
							html+="<a href=\"{:U('HelpCategory/delete')}&id="+result.data[x]['id']+"\" onclick=\"return confirm('你确定要删除吗？')\" >删除</a>"; 
							html+="</div>"; 
							html+="<div class=\"clear\"></div>"; 
							html+="</div>"; 
							html+="</div>";
                            i++;
                        }
						html+="<div class=\"smalladd l"+level+"\"><div class=\"J_add adds \" level=\""+level+"\" parentid=\""+pid+"\">添加分类</div></div>";
						thisobj.after('<div class="j_smalldiv">'+html+'</div>');  
				
						  
                    }
                 }
            );
}
});
</script>
</body>
</html>